export default {
    GetQueryString : function(name) {

    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);

    if (r != null) return unescape(r[2]);
    return null;

  },

  
  uid : function() {
    let s = [];
    let hexDigits = "abcdef0123456789";
    for (var i = 0; i < 36; i++) {
      s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
    }
    s[14] = "6";
    s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
    s[8] = s[13] = s[18] = s[23] = "-";

    return s.join("");
  },

   api : '',
  //  api : '/api',
   loadJs: function(sid, jsurl, ele, callback) {
    try {
      var nodeHead = document.getElementsByTagName("head")[0];

      var nodeScript = null;

      if (document.getElementById(sid) == null) {
        nodeScript = document.createElement(ele);
        if (ele == "script") {
          nodeScript.setAttribute("type", "text/javascript");
          nodeScript.setAttribute("src", jsurl);
        } else if (ele == "link") {
          nodeScript.setAttribute("rel", "stylesheet");
          nodeScript.setAttribute("href", jsurl);
        }

        nodeScript.setAttribute("id", sid);
        nodeHead.appendChild(nodeScript);

        if (callback != null) {
          nodeScript.onload = nodeScript.onreadystatechange = function() {
            if (nodeScript.ready) {
              return false;
            }
            if (
              !nodeScript.readyState ||
              nodeScript.readyState == "complete"
            ) {
              nodeScript.ready = true;
              callback();
            }
          };
        }
      } else {
        if (callback != null) {
          callback();
        }
      }
    } catch (e) {
      console.log("错误了" + e);
    }
  },
}
  